﻿using Architecture.API.Application.TraceabilityCommand.ShoppingCommand;
using MediatR;
using Traceability.Domain;
using Traceability.Domain.Service.ShoppingServices;
using Traceability.Domain.TraceabilityDto;

namespace Architecture.API.Application.TraceabilityCommandHandler.ShoppingCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class ShoppingUpdateCommandHandler : IRequestHandler<ShoppingUpdateCommand, int>
    {
        /// <summary>
        /// 商品服务
        /// </summary>
        protected readonly IShoppingService shoppingService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="shoppingService">商品服务</param>
        public ShoppingUpdateCommandHandler(IShoppingService shoppingService)
        {
            this.shoppingService = shoppingService;
        }

        /// <summary>
        /// 修改商品信息
        /// </summary>
        /// <param name="request">请求信息</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(ShoppingUpdateCommand request, CancellationToken cancellationToken)
        {
            return await shoppingService.UpdateShopping(new UpdateShoppingDto() { ShoppingId=request.ShoppingId,ProductionBatch=request.ProductionBatch, QGPeriod=request.QGPeriod,ProductionLicense=request.ProductionLicense,ManufacturingEnterprise=request.ManufacturingEnterprise,PictureId=request.PictureId,ShoppingNameId=request.ShoppingNameId,CreatedBy=request.CreatedBy,CreatedDate=request.CreatedDate,UpdatedBy=request.UpdatedBy,UpdatedDate=DateTime.Now,DeletedBy=request.DeletedBy,DeletedDate=request.DeletedDate,IsDeleted=request.IsDeleted });
        }
    }
}
